import struct

import torch
from torch.utils.data import Dataset
import numpy as np
import os

import VoxDataset


class IOUtester:
    #读入原模型和重建后模型，做对比
    def __init__(self, originpath, rebuildpath):
        with open(originpath, 'rb') as f:
            self.origindata = VoxDataset.VoxDataset(f)

        with open(rebuildpath, 'rb') as f:
            self.rebuilddata = VoxDataset.VoxDataset(f)

        self.i = 0
        self.u = 0

    #IOU的定义是交集除并集
    def calculate(self):
        for i in range(self.origindata.__len__()):
            temp1, flag1 = self.origindata.__getitem__(i)
            temp2, flag2 = self.rebuilddata.__getitem__(i)
            if(flag1 or flag2):
                self.u = self.u + 1
            if(flag1 and flag2):
                self.i = self.i + 1
        return self.u, self.i
